package com.chhuang.ewcrm.comm;

import javafx.scene.control.Label;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static javafx.application.Platform.runLater;

/**
 * 红外串口通讯返回成功执行操作类
 */
public class CommInfraRedValue implements CommCallBack {
    private final Logger logger = LoggerFactory.getLogger(CommInfraRedValue.class);

    private final Label infraredLabel1;
    private final Label infraredLabel2;

    private static final String GREEN_BACKGROUND = "-fx-background-color: green";
    private static final String RED_BACKGROUND = "-fx-background-color: red";
    public static final String ORANGE_BACKGROUND = "-fx-background-color: orange";

    public CommInfraRedValue(Label infraredLabel1, Label infraredLabel2){
        this.infraredLabel1 = infraredLabel1;
        this.infraredLabel2 = infraredLabel2;
    }

    private static final String NORMAL_VALUE = "01 06 FF 02 C0 C8"; // 红外正常
    private static final String ABNORMAL_VALUE1 = "01 06 FF 02 C2 CA"; //南红外遮挡
    private static final String ABNORMAL_VALUE2 = "01 06 FF 02 C4 CC"; //北红外遮挡

    public static final String LINGHT1_GREEN = "01 06 AA 03 08 BC";
    public static final String LINGHT1_RED = "01 06 AA 03 04 B8";
    public static final String LINGHT2_GREEN = "01 06 AA 03 02 B6";
    public static final String LINGHT2_RED = "01 06 AA 03 01 B5";

    @Override
    public void doSuccess(String hexStr) {
        if(NORMAL_VALUE.equalsIgnoreCase(hexStr)){
//            logger.debug("CommInfraRedValue:红外正常");
            runLater(() -> {
                infraredLabel1.setStyle(GREEN_BACKGROUND);
                infraredLabel2.setStyle(GREEN_BACKGROUND);
            });
        }else if(ABNORMAL_VALUE1.equalsIgnoreCase(hexStr)){
            logger.debug("CommInfraRedValue:南红外遮挡");
            runLater(() ->  infraredLabel1.setStyle(RED_BACKGROUND));
        }else if(ABNORMAL_VALUE2.equalsIgnoreCase(hexStr)){
            logger.debug("CommInfraRedValue:北红外遮挡");
            runLater(() -> infraredLabel2.setStyle(RED_BACKGROUND));
        }else {
            runLater(() -> {
                infraredLabel1.setStyle(ORANGE_BACKGROUND);
                infraredLabel2.setStyle(ORANGE_BACKGROUND);
            });
            logger.debug("CommInfraRedValue:"+hexStr);
        }
    }
}
